import com.cherry.mybatis.Dept;
import com.cherry.mybatis.Emp;
import com.cherry.mybatis.dao.EmpDeptDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class T03 {

    @Test
    public void q01() throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sessionFactory.openSession();
        EmpDeptDao empDeptDao = session.getMapper(EmpDeptDao.class);
        List<Emp> list = empDeptDao.findAllEmp();
        System.out.println(list);
        session.close();

    }

    @Test
    public void q02() throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sessionFactory.openSession();
        EmpDeptDao empDeptDao = session.getMapper(EmpDeptDao.class);
        List<Dept> list = empDeptDao.findAllDept();
        System.out.println(list);
        session.close();

    }


    @Test
    public void q03() throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sessionFactory.openSession();
        EmpDeptDao empDeptDao = session.getMapper(EmpDeptDao.class);
        List<Emp> list = empDeptDao.findAllEmpWithRole();
        System.out.println(list);
        session.close();

    }


}
